\chapter{Building and Installing}
The \adevs\ package is organized into the following directory structure:
\begin{verbatim}
adevs-x.y.z
           +->docs
           +->examples
           +->include
           +->src
           +->test
           +->util
\end{verbatim}
The \adevs\ simulation engine is comprised almost entirely of template classes, and these are implemented in the header files located in the \filename{include} directory. The exceptions are the random number generators, the Java language bindings, and some aspects of the parallel simulation engine. If you do not want to use these features then its sufficient for your program to include \filename{adevs.h} and to be sure your compiler can find the \filename{include} directory that \filename{adevs.h} is in. 

If you want to use the random number generators or parallel simulation engine, then you must build the adevs static library. To do this, enter the \filename{src} directory and execute the command 'make' if you are using a Linux system or 'build' if you are using Windows. On Windows, the batch file creates a static library called \filename{adevs.lib}. For Linux systems, the makefile creates a static library called \filename{libadevs.a}.

If you are using a Windows system, the batch file must be executed from the Visual C++ command prompt. This will ensure the batch file can find the compiler, linker, and necessary system header files. For Linux systems, make sure you have a recent version of the GNU C++ compiler and GNU make. You may need to edit the makefile (i.e., the file \filename{Makefile}) to set compiler flags, etc. but the defaults should work in most cases.

To build the Java language bindings, you need to have the Oracle JDK or something that is compatible with it (such as the OpenJDK). On a Windows system, from the \filename{src} directory enter the \filename{adevs\_jni} directory and then execute the command 'build'. This creates three files: \filename{adevs.jar}, \filename{java\_adevs.dll}, and \filename{java\_adevs.lib}. To build and run your Java programs, you will need to put \filename{adevs.jar} into your classpath and \filename{java\_adevs.dll} into your java.library.path (or make sure it is in your regular PATH for finding executables and dynamic link libraries).

On a Linux system, stay in the \filename{src} directory and execute the command 'make java\_adevs'. This creates two files: \filename{adevs.jar} and \filename{libjava\_adevs.so}. As before, you need to put \filename{adevs.jar} into your classpath and \filename{libjava\_adevs.so} into your java.library.path or make sure it is in your LD\_LIBRARY\_PATH for locating dynamic link libraries.

\adevs\ includes some support for simulating importing models that support the Functional Mockup Interface for Model Exchange standard (models built with most Modelica based tools support this standard). If you want to experiment with this feature you can get and build the OpenModelica compiler. For this purpose, the shell script \filename{build-omc.sh} is provided in the \filename{util} directory. This shell script does the following: 1) creates the directory \filename{openmodelica} at the location where the script is run, 2) fetches the minimal set of packages that are needed to compile the OpenModelica compiler, and 3) fetches and builds a bare-bones OpenModelica compiler. The compiler is called \filename{omc} and it is located in the directory \filename{openmodelica/trunk/build/bin}. You will also need to get the FMI header files from \url{https://www.fmi-standard.org/downloads} and include \filename{adevs\_fmi.h} in your program files.

To run the test suite (which is not required to use the software), you must build the static library file and install Tcl (the test scripts need Tcl to run; if you can run `tclsh' then you already have a working copy of Tcl). If you want to test the Java bindings then you will need to build them; to test the FMI support you will need the OpenModelica compiler. There are four sets of tests that can be executed: one for the serial simulation engine, one for the parallel simulation engine, one for the Java language bindings, and one for the FMI support.

To run the tests for the serial simulation engine, use 'make check\_cpp'. To run the tests for the parallel simulation engines use 'make check\_par' (note: the environment variable OMP\_NUM\_THREADS must be set to at least four). To run the Java test cases, use 'make java\_test'. To run the FMI test cases, put the omc compiler into your PATH and run 'make check\_fmi'. To run all of the test cases, use 'make'. The test script will abort when any test fails. If the test script run to completion, then all of the tests passed.

The test cases can be a bit of a bear to run on a Windows computer. If you need to edit compiler settings, executable directives, etc. to make it work, then modify the file \filename{make.common}. For Linux systems using the GNU tools the test cases should work out of the box. Otherwise, edit \filename{make.common} to fix things to fit your development environment.
